package com.example.最大社交距离;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author: 唐佳辉
 * @CreateTime： 2024-06-14-下午5:11
 * @Description:
 * @Version：1.0
 */

public class Main {
    public static int updateSeatsIn(List<Integer> seats) {
        int n = seats.size();
        int right = n - 1;
        for (int i = n - 1; i >= 0; i--) {
            if (seats.get(i) == 1) {
                right = i;
                break;
            }
        }

        int ansIdx = n - 1;
        int maxDis = n - 1 - right;
        int pre = 0;
        for (int i = 1; i <= right; i++) {
            if (seats.get(i) == 1) {
                int curDis = (i - pre) / 2;
                if (maxDis < curDis) {
                    maxDis = curDis;
                    ansIdx = pre + (i - pre) / 2;
                }
                pre = i;
            }
        }
        return maxDis > 0 ? ansIdx : -1;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine(); // Consume newline
        String line = scanner.nextLine();
        String[] operationsStr = line.substring(1, line.length() - 1).split(", ");
        List<Integer> operations = new ArrayList<>();
        for (String op : operationsStr) {
            operations.add(Integer.parseInt(op));
        }

        List<Integer> seats = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            seats.add(0);
        }
        seats.set(0, 1);

        int lastInOperationIdx = -1;
        for (int i = operations.size() - 1; i >= 0; i--) {
            if (operations.get(i) > 0) {
                lastInOperationIdx = i;
                break;
            }
        }

        if (lastInOperationIdx == 0) {
            System.out.println(0);
        } else {
            for (int i = 1; i <= lastInOperationIdx; i++) {
                if (i == lastInOperationIdx) {
                    int ans = updateSeatsIn(seats);
                    System.out.println(ans);
                    break;
                }
                int op = operations.get(i);
                if (op > 0) {
                    int idx = updateSeatsIn(seats);
                    if (idx != -1) {
                        seats.set(idx, 1);
                    }
                } else {
                    int idx = -op;
                    seats.set(idx, 0);
                }
            }
        }
    }
}

